import { IDomEditor, IButtonMenu } from '@wangeditor/editor';

// 定义自定义菜单类
export class insertTitle implements IButtonMenu {
	title: string;
	tag: string;
	iconSvg?: string;
	alwaysEnable?: boolean;

	constructor() {
		this.title = "标题格式";
		this.tag = "button";
	}

	getValue(editor: IDomEditor): string | boolean {
		return "";
	}

	isActive(editor: IDomEditor): boolean {
		return false;
	}

	isDisabled(editor: IDomEditor): boolean {
		return false;
	}

	exec(editor: IDomEditor, value: string | boolean) {
		if (!editor.selection) return;

		// 1. 获取选中文本
		const selectedText = editor.getSelectionText();

		// 2. 创建要替换的HTML内容
		const newHtml = `
			<p style="
				line-height: 1.5; 
				text-align: center; 
				width: 100%;
				font-weight: bold; 
				font-size: 29px; 
				text-align: justify;
			">
				<span style="
					font-family: song;
					font-size: 29px;
					font-weight: bold; 
					margin-bottom: 10px;
					display: inline-block;
				">${selectedText}</span>
			</p>
			<br/>`;

		// 3. 替换选中内容
		editor.dangerouslyInsertHtml(newHtml);
	}
}
